package com.qf.shiro2203.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/*作弊工具*/
@Component
public class ApplicationContextUtils implements ApplicationContextAware {

    private  static ApplicationContext ctx;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ctx=applicationContext;
    }

    public static Object getBean(String bename){
        return ctx.getBean(bename);
    }

    /**
     * 根据传入的class对象获取IOC容器中的bean
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T getBean(Class<T> clazz){

        T bean = ctx.getBean(clazz);
        return bean;
    }
}
